package com.dlry.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dlry.db.LeaveRepository;
import com.dlry.entity.DlLeave;


@Service
@Transactional
public class LeaveServiceImpl implements LeaveService {

	@Autowired
	private LeaveRepository leaveRepository;

	public void save(DlLeave leave) {
		leaveRepository.save(leave);
	}

	public void update(DlLeave leave) {
		leaveRepository.save(leave);
	}

	public void delete(Long lId) {
		leaveRepository.delete(lId);
	}

	public DlLeave findOne(Long lId) {
		return leaveRepository.findOne(lId);
	}

	public Page<DlLeave> findAll(Integer page, Integer row) {
		Sort sort = new Sort(Direction.DESC, "createdDate");
		Pageable pageable = new PageRequest(page, row, sort );
		return leaveRepository.findAll(pageable);
	}


}
